<template>
  <div class="app-container">
    <el-row class="search">
      <el-select
        v-model="query.t"
        style="margin-right: 8px; width: 120px"
        placeholder="日期类型"
      >
        <el-option
          v-for="item in [
            { label: '出院日期', value: '出院日期' },
            { label: '入院日期', value: '入院日期' },
          ]"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>

      <el-date-picker
        v-model="query.stime"
        style="width: 150px"
        type="date"
        placeholder="开始"
        value-format="yyyy-MM-dd"
      >
      </el-date-picker>
      <span>-</span>
      <el-date-picker
        v-model="query.etime"
        style="width: 150px"
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="结束"
      >
      </el-date-picker>

      <el-button type="warning" @click="search" round
        >搜&nbsp;&nbsp;索</el-button
      >
    </el-row>

    <el-row>
      <el-table
        :data="ls"
        stripe
        style="width: 100%"
        v-loading="sLoading"
        height="500"
      >
        <el-table-column prop="科室" label="科室"> </el-table-column>
        <el-table-column prop="总人次" label="总人次" sortable>
        </el-table-column>
        <el-table-column prop="入组人次" label="DRG入组人次" sortable>
        </el-table-column>
        <el-table-column prop="是否入径" sortable label="入径人次">
        </el-table-column>
        <el-table-column
          prop="入径率"
          sortable
          :formatter="fmt"
          label="入径率(%)"
        >
          <template slot-scope="scope"
            ><span>{{ fmt(scope.row, "入径率") }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="费用超标" sortable :label="'费用超标占比'">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.费用超标"
              placement="right"
            >
              <span>{{ fmt(scope.row, "费用超标") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="治疗不足" sortable :label="'治疗不足占比'">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.治疗不足"
              placement="right"
            >
              <span>{{ fmt(scope.row, "治疗不足") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column prop="费用极低" sortable :label="'费用极低占比'">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.费用极低"
              placement="right"
            >
              <span>{{ fmt(scope.row, "费用极低") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column prop="费用极高" sortable :label="'费用极高占比'">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.费用极高"
              placement="right"
            >
              <span>{{ fmt(scope.row, "费用极高") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column
          prop="费用结构不合理"
          sortable
          :label="'费用结构不合理占比'"
        >
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.费用结构不合理"
              placement="right"
            >
              <span>{{ fmt(scope.row, "费用结构不合理") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column
          prop="违规项目较多"
          sortable
          :label="'违规项目较多占比'"
        >
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.违规项目较多"
              placement="right"
            >
              <span>{{ fmt(scope.row, "违规项目较多") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          prop="并发症消耗过大"
          sortable
          :label="'并发症消耗过大占比'"
        >
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.并发症消耗过大"
              placement="right"
            >
              <span>{{ fmt(scope.row, "并发症消耗过大") }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { tplDetail, saveTpl, drgNames, drgInfo } from "@/api/PathTemplate";
import { drgwaring } from "@/api/patient";
import { GetTplById } from "@/api/pathway";
import { Format } from "@/utils/Utils";
import { autoName } from "@/api/commonApi";
@Component({
  name: "drgwarning",
})
export default class extends Vue {
  public query = {
    t: "出院日期",
    stime: "" || this.$route.query.stime,
    etime: this.$route.query.etime || this.Format("yyyy-MM-dd", new Date()),
  };

  public fmt(row: any, column: any) {
    let property = column;

    if (property == "入径率") {
      if (row.入组人次) {
        return (((row.是否入径 * 1.0) / row.入组人次) * 100).toFixed(2);
      }
    }
    if (row.是否入径 > 0) {
      return (((row[property] * 1.0) / row.是否入径) * 100).toFixed(2);
    }
    return 0;
  }
  private created() {
    let cDate = new Date();
    let m = cDate.getMonth() - ((<any>window).MyConf["TIMEINTERVAL"] || "1");
    cDate.setMonth(m);
    if (!this.query.stime) {
      this.query.stime = this.Format("yyyy-MM-dd", cDate);
    }
    this.search();
  }

  public ls: Array<any> = [];
  public sLoading: boolean = false;

  public async search() {
    this.sLoading = true;
    const { data } = await drgwaring(this.query);
    this.ls = data;
    this.sLoading = false;
  }
  private Format(fmt: string, date: Date) {
    //author: meizz
    var o: any = {
      "M+": date.getMonth() + 1, //月份
      "d+": date.getDate(), //日
      "h+": date.getHours(), //小时
      "m+": date.getMinutes(), //分
      "s+": date.getSeconds(), //秒
      "q+": Math.floor((date.getMonth() + 3) / 3), //季度
      S: date.getMilliseconds(), //毫秒
    };
    if (/(y+)/.test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        (date.getFullYear() + "").substr(4 - RegExp.$1.length)
      );
    for (var k in o) {
      if (new RegExp("(" + k + ")").test(fmt)) {
        fmt = fmt.replace(
          RegExp.$1,
          RegExp.$1.length == 1
            ? o[k]
            : ("00" + o[k]).substr(("" + o[k]).length)
        );
      }
    }

    return fmt;
  }
}
</script>